package com.qingcheng.controller.goods;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.goods.StockBack;
import com.qingcheng.service.goods.SkuService;
import com.qingcheng.service.goods.StockBackService;
import com.qingcheng.service.order.CategoryReportService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class StockBackTask {

    @Reference
    private StockBackService stockBackService;

    @Reference
    private SkuService skuService;
    @Scheduled(cron = "0/1 * * * * ?")
    public void stockBack() {
        /**
         * 进行库存回滚的任务
         */
        //1. 读取哪些商品需要进行回滚  stock_back   select * from tb_stock_back wehere state='0'
        List<StockBack> stockBacks = stockBackService.queryAll();
        //2.混滚数据    update  tb_sku set num = num+ xxx ,sale_num = num - xxx wehre sku = xx
        skuService.stockBack(stockBacks);
        //3.讲已经进行回滚的记录状态变成1  update tb_stock_back set state = '1' where order_id = xx ,sku_id = xxx
        stockBackService.updateState(stockBacks);  //1

    }


}
